<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="小程序," />





  <link rel="alternate" href="/atom.xml" title="尛孟的博客" type="application/atom+xml" />






<meta name="description" content="map 地图  不能在 scroll-view、swiper、picker-view、movable-view 中使用 map 组件。 map 组件使用的经纬度是火星坐标系，调用 wx.getLocation 接口需要指定 type 为 gcj02 可以用wx.createMapContext获取地图上下文   12345&amp;lt;map id=&quot;map&quot; longitude=&quot;&amp;#123;&amp;#1">
<meta name="keywords" content="小程序">
<meta property="og:type" content="article">
<meta property="og:title" content="小程序-组件-地图&amp;画布">
<meta property="og:url" content="http://yoursite.com/2018/01/16/小程序-组件-地图-画布/index.html">
<meta property="og:site_name" content="尛孟的博客">
<meta property="og:description" content="map 地图  不能在 scroll-view、swiper、picker-view、movable-view 中使用 map 组件。 map 组件使用的经纬度是火星坐标系，调用 wx.getLocation 接口需要指定 type 为 gcj02 可以用wx.createMapContext获取地图上下文   12345&amp;lt;map id=&quot;map&quot; longitude=&quot;&amp;#123;&amp;#1">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://www.z4a.net/images/2018/01/16/_20180116162650.png">
<meta property="og:updated_time" content="2018-01-16T09:03:55.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="小程序-组件-地图&amp;画布">
<meta name="twitter:description" content="map 地图  不能在 scroll-view、swiper、picker-view、movable-view 中使用 map 组件。 map 组件使用的经纬度是火星坐标系，调用 wx.getLocation 接口需要指定 type 为 gcj02 可以用wx.createMapContext获取地图上下文   12345&amp;lt;map id=&quot;map&quot; longitude=&quot;&amp;#123;&amp;#1">
<meta name="twitter:image" content="http://www.z4a.net/images/2018/01/16/_20180116162650.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"hide","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: 'ZNJ0RM31SP',
      apiKey: '9fae47ade11c769ab25bba4061522c1d',
      indexName: 'for_meng',
      hits: {"per_page":10},
      labels: {"input_placeholder":"输入关键词进行搜索","hits_empty":" 找不到关于 ”${query}“ 的文章 ","hits_stats":" 共找到${hits} 篇文章,花了${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/01/16/小程序-组件-地图-画布/"/>




<script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
<link href="//cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">


  <title>小程序-组件-地图&画布 | 尛孟的博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">尛孟的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">想法总是无法付诸实践…</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/01/16/小程序-组件-地图-画布/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="尛孟">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="尛孟的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">小程序-组件-地图&画布</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-01-16T15:48:44+08:00">
                2018-01-16
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/小程序/" itemprop="url" rel="index">
                    <span itemprop="name">小程序</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/小程序/框架学习/" itemprop="url" rel="index">
                    <span itemprop="name">框架学习</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/小程序/框架学习/组件/" itemprop="url" rel="index">
                    <span itemprop="name">组件</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/01/16/小程序-组件-地图-画布/" class="leancloud_visitors" data-flag-title="小程序-组件-地图&画布">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <hr>
<h3 id="map"><a href="#map" class="headerlink" title="map"></a>map</h3><blockquote>
<p>地图</p>
<blockquote>
<p>不能在 <code>scroll-view、swiper、picker-view、movable-view</code> 中使用 map 组件。</p>
<p><strong>map 组件使用的经纬度是火星坐标系，调用 <code>wx.getLocation</code> 接口需要指定 type 为 gcj02</strong></p>
<p>可以用<code>wx.createMapContext</code>获取地图上下文</p>
</blockquote>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">map</span> <span class="attr">id</span>=<span class="string">"map"</span> <span class="attr">longitude</span>=<span class="string">"&#123;&#123;longitude&#125;&#125;"</span> <span class="attr">latitude</span>=<span class="string">"&#123;&#123;latitude&#125;&#125;"</span> <span class="attr">scale</span>=<span class="string">"14"</span> <span class="attr">controls</span>=<span class="string">"&#123;&#123;controls&#125;&#125;"</span></span></span><br><span class="line"><span class="tag"><span class="attr">bindcontroltap</span>=<span class="string">"controltap"</span> <span class="attr">markers</span>=<span class="string">"&#123;&#123;markers&#125;&#125;"</span> <span class="attr">bindmarkertap</span>=<span class="string">"markertap"</span></span></span><br><span class="line"><span class="tag"><span class="attr">polyline</span>=<span class="string">"&#123;&#123;polyline&#125;&#125;"</span> <span class="attr">circles</span>=<span class="string">"&#123;&#123;circles&#125;&#125;"</span> <span class="attr">bindregionchange</span>=<span class="string">"regionchange"</span> </span></span><br><span class="line"><span class="tag"><span class="attr">show-location</span> <span class="attr">style</span>=<span class="string">"width: 100%; height: 350px;"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">map</span>&gt;</span>   <span class="comment">&lt;!-- 显示基本地图 --&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="markers–标注，polyline–折线，circles–圆形，controls–控件"><a href="#markers–标注，polyline–折线，circles–圆形，controls–控件" class="headerlink" title="markers–标注，polyline–折线，circles–圆形，controls–控件"></a>markers–标注，polyline–折线，circles–圆形，controls–控件</h4><ul>
<li><h5 id="markers"><a href="#markers" class="headerlink" title="markers"></a>markers</h5><p>除了显示基本的地图,还可以在地图上添加大头针标识</p>
<blockquote>
<p>需要传入marker的经纬度、显示的图标</p>
<p>点击marker时会调用map的bindmarkertap事件</p>
<p>每一个marker最好设置上Number类型的id,保证更新时性能更好</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">markers: [&#123;</span><br><span class="line">  <span class="comment">//显示图标</span></span><br><span class="line">      iconPath: <span class="string">"/resources/others.png"</span>,</span><br><span class="line">  <span class="comment">//marker的id</span></span><br><span class="line">      id: <span class="number">0</span>,</span><br><span class="line">  <span class="comment">//经纬度</span></span><br><span class="line">      latitude: <span class="number">23.099994</span>,</span><br><span class="line">      longitude: <span class="number">113.324520</span>,</span><br><span class="line">  <span class="comment">//图标宽高</span></span><br><span class="line">      width: <span class="number">50</span>,</span><br><span class="line">      height: <span class="number">50</span></span><br><span class="line">    &#125;],</span><br></pre></td></tr></table></figure>
<p><img src="http://www.z4a.net/images/2018/01/16/_20180116162650.png" alt="大头针标识"></p>
</li>
<li><h5 id="callout"><a href="#callout" class="headerlink" title="callout"></a>callout</h5><p>在marker上显示出气泡label</p>
<p>点击气泡时调起map的bindcallouttap事件</p>
<blockquote>
<p>只是显示文本标题,不是点击后弹框</p>
</blockquote>
</li>
<li><h5 id="polyline"><a href="#polyline" class="headerlink" title="polyline"></a>polyline</h5><p>指定一系列坐标点,然后会在地图上连成一条线,可以用来做运动轨迹</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">polyline: [&#123;</span><br><span class="line">      points: [&#123;  <span class="comment">//经纬度数组</span></span><br><span class="line">        longitude: <span class="number">113.3245211</span>,</span><br><span class="line">        latitude: <span class="number">23.10229</span></span><br><span class="line">      &#125;, &#123;</span><br><span class="line">        longitude: <span class="number">113.324520</span>,</span><br><span class="line">        latitude: <span class="number">23.21229</span></span><br><span class="line">      &#125;],</span><br><span class="line">  <span class="comment">//线的颜色</span></span><br><span class="line">      color:<span class="string">"#FF0000DD"</span>,</span><br><span class="line">  <span class="comment">//线宽</span></span><br><span class="line">      width: <span class="number">2</span>,</span><br><span class="line">  <span class="comment">//是否虚线</span></span><br><span class="line">      dottedLine: <span class="literal">true</span>,</span><br><span class="line">  <span class="comment">//是否带箭头   可以通过arrowIconPath更换箭头的图标</span></span><br><span class="line">  	  arrowLine: <span class="literal">false</span>,  </span><br><span class="line">    &#125;],</span><br></pre></td></tr></table></figure>
</li>
<li><h5 id="circles"><a href="#circles" class="headerlink" title="circles"></a>circles</h5><p>在地图上画出一个圆</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">circles: [&#123;</span><br><span class="line">  <span class="comment">//经纬度</span></span><br><span class="line">      latitude: <span class="string">'40.007153'</span>,</span><br><span class="line">      longitude: <span class="string">'116.491081'</span>,</span><br><span class="line">  <span class="comment">//描边的颜色</span></span><br><span class="line">      color: <span class="string">'#FF0000DD'</span>,</span><br><span class="line">  <span class="comment">//填充颜色</span></span><br><span class="line">      fillColor: <span class="string">'#7cb5ec88'</span>,</span><br><span class="line">  <span class="comment">//半径</span></span><br><span class="line">      radius: <span class="number">400</span>,</span><br><span class="line">  <span class="comment">//描边的宽度</span></span><br><span class="line">      strokeWidth: <span class="number">2</span></span><br><span class="line">    &#125;],</span><br></pre></td></tr></table></figure>
</li>
<li><h5 id="controls"><a href="#controls" class="headerlink" title="controls"></a>controls</h5><p>在地图上显示控件,控件不会随着地图移动</p>
<p>点击控件时会调起map的bindcontroltap事件</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">controls: [&#123;</span><br><span class="line">  <span class="comment">//控件id</span></span><br><span class="line">      id: <span class="number">1</span>,</span><br><span class="line">  <span class="comment">//显示的图标</span></span><br><span class="line">      iconPath: <span class="string">'/resources/location.png'</span>,</span><br><span class="line">  <span class="comment">//控件在地图上的位置</span></span><br><span class="line">      position: &#123;</span><br><span class="line">        left: <span class="number">0</span>,</span><br><span class="line">        top: <span class="number">300</span> - <span class="number">50</span>,</span><br><span class="line">        width: <span class="number">50</span>,</span><br><span class="line">        height: <span class="number">50</span></span><br><span class="line">      &#125;,</span><br><span class="line">  <span class="comment">//是否可以点击</span></span><br><span class="line">      clickable: <span class="literal">true</span></span><br><span class="line">    &#125;]</span><br></pre></td></tr></table></figure>
</li>
</ul>
<hr>
<h3 id="canvas"><a href="#canvas" class="headerlink" title="canvas"></a>canvas</h3><blockquote>
<p>画布</p>
<blockquote>
<p>同一页面中的 canvas-id 不可重复，如果使用一个已经出现过的 canvas-id，该 canvas 标签对应的画布将被隐藏并不再正常工作</p>
<p>不能在 <code>scroll-view、swiper、picker-view、movable-view</code> 中使用 canvas 组件。</p>
<p>同过调用<code>x.createCanvasContext</code>来获取画布上下文</p>
</blockquote>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">canvas</span> <span class="attr">style</span>=<span class="string">"width: 300px; height: 200px;"</span> <span class="attr">canvas-id</span>=<span class="string">"firstCanvas"</span>&gt;</span><span class="tag">&lt;/<span class="name">canvas</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 当使用绝对定位时，文档流后边的 canvas 的显示层级高于前边的 canvas --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">canvas</span> <span class="attr">style</span>=<span class="string">"width: 400px; height: 500px;"</span> <span class="attr">canvas-id</span>=<span class="string">"secondCanvas"</span>&gt;</span><span class="tag">&lt;/<span class="name">canvas</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 因为 canvas-id 与前一个 canvas 重复，该 canvas 不会显示，并会发送一个错误事件到 AppService --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">canvas</span> <span class="attr">style</span>=<span class="string">"width: 400px; height: 500px;"</span> <span class="attr">canvas-id</span>=<span class="string">"secondCanvas"</span> <span class="attr">binderror</span>=<span class="string">"canvasIdErrorCallback"</span>&gt;</span><span class="tag">&lt;/<span class="name">canvas</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">Page(&#123;</span><br><span class="line">  canvasIdErrorCallback: <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span><br><span class="line">    <span class="comment">//发生错误</span></span><br><span class="line">    <span class="built_in">console</span>.error(e.detail.errMsg)</span><br><span class="line">  &#125;,</span><br><span class="line">  onReady: <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 使用 wx.createContext 获取绘图上下文 context</span></span><br><span class="line">    <span class="keyword">var</span> context = wx.createCanvasContext(<span class="string">'firstCanvas'</span>)</span><br><span class="line">	</span><br><span class="line">    <span class="comment">//绘制一个矩形</span></span><br><span class="line">    context.setStrokeStyle(<span class="string">"#00ff00"</span>)</span><br><span class="line">    context.setLineWidth(<span class="number">5</span>)</span><br><span class="line">    context.rect(<span class="number">0</span>, <span class="number">0</span>, <span class="number">200</span>, <span class="number">200</span>)</span><br><span class="line">    context.stroke()</span><br><span class="line">     <span class="comment">/**</span></span><br><span class="line"><span class="comment">     *  也可以直接调用wx.drawCanvas，通过canvasId指定在哪张画布上绘制,通过actions指定绘制行为</span></span><br><span class="line"><span class="comment">     *  注意convasId可以为数字表示也可以用字符串表示，就是一个绘制对象的标识，并且可以指定多个</span></span><br><span class="line"><span class="comment">        wx.drawCanvas(&#123;</span></span><br><span class="line"><span class="comment">      		//画布标识，传入&lt;canvas/&gt;的cavas-id</span></span><br><span class="line"><span class="comment">      		canvasId: 'identify',</span></span><br><span class="line"><span class="comment">      		//获取绘制行为， 把这个上下文的绘制"画到指定画布"</span></span><br><span class="line"><span class="comment">      		actions: context.getActions(),</span></span><br><span class="line"><span class="comment">   		 &#125;)</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    context.setStrokeStyle(<span class="string">"#ff0000"</span>)</span><br><span class="line">    context.setLineWidth(<span class="number">2</span>)</span><br><span class="line">    context.moveTo(<span class="number">160</span>, <span class="number">100</span>)</span><br><span class="line">    context.arc(<span class="number">100</span>, <span class="number">100</span>, <span class="number">60</span>, <span class="number">0</span>, <span class="number">2</span> * <span class="built_in">Math</span>.PI, <span class="literal">true</span>)</span><br><span class="line">    context.moveTo(<span class="number">140</span>, <span class="number">100</span>)</span><br><span class="line">    context.arc(<span class="number">100</span>, <span class="number">100</span>, <span class="number">40</span>, <span class="number">0</span>, <span class="built_in">Math</span>.PI, <span class="literal">false</span>)</span><br><span class="line">    context.moveTo(<span class="number">85</span>, <span class="number">80</span>)</span><br><span class="line">    context.arc(<span class="number">80</span>, <span class="number">80</span>, <span class="number">5</span>, <span class="number">0</span>, <span class="number">2</span> * <span class="built_in">Math</span>.PI, <span class="literal">true</span>)</span><br><span class="line">    context.moveTo(<span class="number">125</span>, <span class="number">80</span>)</span><br><span class="line">    context.arc(<span class="number">120</span>, <span class="number">80</span>, <span class="number">5</span>, <span class="number">0</span>, <span class="number">2</span> * <span class="built_in">Math</span>.PI, <span class="literal">true</span>)</span><br><span class="line">    context.stroke()</span><br><span class="line">    context.draw()</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<hr>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/小程序/" rel="tag"># 小程序</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/01/16/小程序-组件-媒体组件/" rel="next" title="小程序-组件-媒体组件">
                <i class="fa fa-chevron-left"></i> 小程序-组件-媒体组件
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/01/16/小程序-API-网络/" rel="prev" title="小程序-API-网络">
                小程序-API-网络 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">尛孟</p>
              <p class="site-description motion-element" itemprop="description">与人联系甚少</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">26</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#map"><span class="nav-number">1.</span> <span class="nav-text">map</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#markers–标注，polyline–折线，circles–圆形，controls–控件"><span class="nav-number">1.1.</span> <span class="nav-text">markers–标注，polyline–折线，circles–圆形，controls–控件</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#markers"><span class="nav-number">1.1.1.</span> <span class="nav-text">markers</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#callout"><span class="nav-number">1.1.2.</span> <span class="nav-text">callout</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#polyline"><span class="nav-number">1.1.3.</span> <span class="nav-text">polyline</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#circles"><span class="nav-number">1.1.4.</span> <span class="nav-text">circles</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#controls"><span class="nav-number">1.1.5.</span> <span class="nav-text">controls</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#canvas"><span class="nav-number">2.</span> <span class="nav-text">canvas</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">尛孟</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  




  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.4"></script>



  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("KhsxPkrt4UYiKBnwYFY9zUTN-gzGzoHsz", "a1zezRocQqcmPxlFVdXKrhz9");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  

  

  

</body>
</html>
